home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the 3D Game Programming Gurus / gurus.iso / DirectX / dx9sdkcp.exe / SDK (C++) / Bin / DXUtils / Visual Studio 6.0 Wizards / Source Code / Template / dmutil.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-11-12  |  6.4 KB  |  172 lines

  1. //-----------------------------------------------------------------------------
  2. // File: DMUtil.h
  3. //
  4. // Desc: DirectMusic framework classes for playing DirectMusic segments and
  5. //       DirectMusic scripts. Feel free to use this class as a starting point 
  6. //       for adding extra functionality.
  7. //-----------------------------------------------------------------------------
  8. #ifndef DMUTIL_H
  9. #define DMUTIL_H
  10.  
  11. #include <dmusicc.h>
  12. #include <dmusici.h>
  13. #include <dsound.h>
  14.  
  15.  
  16. //-----------------------------------------------------------------------------
  17. // Classes used by this header
  18. //-----------------------------------------------------------------------------
  19. class CMusicManager;
  20. class CMusicSegment;
  21. class C3DMusicSegment;
  22. class CMusicScript;
  23.  
  24.  
  25.  
  26.  
  27. //-----------------------------------------------------------------------------
  28. // Name: class CMusicManager
  29. // Desc: 
  30. //-----------------------------------------------------------------------------
  31. class CMusicManager
  32. {
  33. protected:
  34.     BOOL                      m_bCleanupCOM;
  35.     IDirectMusicLoader8*      m_pLoader;
  36.     IDirectMusicPerformance8* m_pPerformance;
  37.     IDirectSound3DListener*   m_pDSListener;
  38.     DS3DLISTENER              m_dsListenerParams;                // Listener properties
  39.  
  40. public:
  41.     CMusicManager();
  42.     ~CMusicManager();
  43.  
  44.     inline IDirectMusicLoader8*      GetLoader()      { return m_pLoader; }
  45.     inline IDirectMusicPerformance8* GetPerformance() { return m_pPerformance; }
  46.     inline IDirectSound3DListener*   GetListener()    { return m_pDSListener; }
  47.  
  48.     IDirectMusicAudioPath8* GetDefaultAudioPath();
  49.  
  50.     HRESULT Initialize( HWND hWnd, DWORD dwPChannels = 128, DWORD dwDefaultPathType = DMUS_APATH_DYNAMIC_STEREO, LPDIRECTSOUND pDS = NULL  );
  51.  
  52.     HRESULT SetSearchDirectory( const TCHAR* strMediaPath );
  53.     VOID    CollectGarbage();
  54.     VOID    StopAll();
  55.  
  56.     HRESULT CreateSegmentFromFile( CMusicSegment** ppSegment, TCHAR* strFileName, 
  57.                                    BOOL bDownloadNow = TRUE, BOOL bIsMidiFile = FALSE );
  58.     HRESULT Create3DSegmentFromFile( C3DMusicSegment** ppSegment, TCHAR* strFileName, 
  59.                                    BOOL bDownloadNow = TRUE, BOOL bIsMidiFile = FALSE, 
  60.                                    IDirectMusicAudioPath8* p3DAudioPath = NULL );
  61.     HRESULT CreateScriptFromFile( CMusicScript** ppScript, TCHAR* strFileName );
  62.  
  63.     HRESULT CreateChordMapFromFile( IDirectMusicChordMap8** ppChordMap, TCHAR* strFileName );
  64.     HRESULT CreateStyleFromFile( IDirectMusicStyle8** ppStyle, TCHAR* strFileName );
  65.     HRESULT GetMotifFromStyle( IDirectMusicSegment8** ppMotif, TCHAR* strStyle, TCHAR* wstrMotif );
  66.  
  67.     HRESULT CreateSegmentFromResource( CMusicSegment** ppSegment, TCHAR* strResource, TCHAR* strResourceType, 
  68.                                    BOOL bDownloadNow = TRUE, BOOL bIsMidiFile = FALSE );
  69.  
  70.     VOID Set3DParameters( FLOAT fDistanceFactor, FLOAT fDopplerFactor, FLOAT fRolloffFactor );
  71. };
  72.  
  73.  
  74.  
  75.  
  76. //-----------------------------------------------------------------------------
  77. // Name: class CMusicSegment
  78. // Desc: Encapsulates functionality of an IDirectMusicSegment
  79. //-----------------------------------------------------------------------------
  80. class CMusicSegment
  81. {
  82. protected:
  83.     IDirectMusicSegment8*     m_pSegment;
  84.     IDirectMusicLoader8*      m_pLoader;
  85.     IDirectMusicPerformance8* m_pPerformance;
  86.     IDirectMusicAudioPath8*   m_pEmbeddedAudioPath;
  87.     BOOL                      m_bDownloaded;
  88.  
  89. public:
  90.     CMusicSegment( IDirectMusicPerformance8* pPerformance, 
  91.                    IDirectMusicLoader8* pLoader,
  92.                    IDirectMusicSegment8* pSegment );
  93.     virtual ~CMusicSegment();
  94.  
  95.     inline  IDirectMusicSegment8* GetSegment() { return m_pSegment; }
  96.     HRESULT GetStyle( IDirectMusicStyle8** ppStyle, DWORD dwStyleIndex = 0 );
  97.  
  98.     HRESULT SetRepeats( DWORD dwRepeats );
  99.     virtual HRESULT Play( DWORD dwFlags = DMUS_SEGF_SECONDARY, IDirectMusicAudioPath8* pAudioPath = NULL );
  100.     HRESULT Stop( DWORD dwFlags = 0 );
  101.     HRESULT Download( IDirectMusicAudioPath8* pAudioPath = NULL );
  102.     HRESULT Unload( IDirectMusicAudioPath8* pAudioPath = NULL );
  103.  
  104.     BOOL    IsPlaying();
  105. };
  106.  
  107.  
  108.  
  109.  
  110. //-----------------------------------------------------------------------------
  111. // Name: class CMusicSegment
  112. // Desc: Encapsulates functionality of an IDirectMusicSegment
  113. //-----------------------------------------------------------------------------
  114. class C3DMusicSegment : public CMusicSegment
  115. {
  116. protected:
  117.     IDirectMusicAudioPath8* m_p3DAudioPath;
  118.     IDirectSound3DBuffer*   m_pDS3DBuffer;
  119.  
  120.     DS3DBUFFER              m_dsBufferParams;                  // 3D buffer properties
  121.     BOOL                    m_bDeferSettings;
  122.     BOOL                    m_bCleanupAudioPath;
  123.  
  124. public:
  125.     C3DMusicSegment( IDirectMusicPerformance8* pPerformance, 
  126.                    IDirectMusicLoader8* pLoader,
  127.                    IDirectMusicSegment8* pSegment,
  128.                    IDirectMusicAudioPath8* pAudioPath );
  129.     virtual ~C3DMusicSegment();
  130.  
  131.     HRESULT Init();
  132.     IDirectMusicAudioPath8* GetAudioPath() { return m_p3DAudioPath; }
  133.     HRESULT Play( DWORD dwFlags = DMUS_SEGF_SECONDARY, IDirectMusicAudioPath8* pAudioPath = NULL );
  134.  
  135.     VOID Set3DParameters( FLOAT fMinDistance,   FLOAT fMaxDistance );
  136.     VOID SetObjectProperties( D3DVECTOR* pvPosition, D3DVECTOR* pvVelocity );
  137. };
  138.  
  139.  
  140.  
  141.  
  142. //-----------------------------------------------------------------------------
  143. // Name: class CMusicScript
  144. // Desc: Encapsulates functionality of an IDirectMusicScript
  145. //-----------------------------------------------------------------------------
  146. class CMusicScript
  147. {
  148. protected:
  149.     IDirectMusicScript8*      m_pScript;
  150.     IDirectMusicLoader8*      m_pLoader;
  151.     IDirectMusicPerformance8* m_pPerformance;
  152.  
  153. public:
  154.     CMusicScript( IDirectMusicPerformance8* pPerformance, 
  155.                   IDirectMusicLoader8* pLoader,
  156.                   IDirectMusicScript8* pScript );
  157.     virtual ~CMusicScript();
  158.  
  159.     inline  IDirectMusicScript8* GetScript() { return m_pScript; }
  160.  
  161.     HRESULT CallRoutine( TCHAR* strRoutine );
  162.     HRESULT SetVariableNumber( TCHAR* strVariable, LONG lValue );
  163.     HRESULT GetVariableNumber( TCHAR* strVariable, LONG* plValue );
  164.     HRESULT SetVariableObject( TCHAR* strVariable, IUnknown *punkValue);
  165.     HRESULT GetVariableObject( TCHAR* strVariable, REFIID riid, LPVOID FAR *ppv);
  166. };
  167.  
  168.  
  169.  
  170.  
  171. #endif // DMUTIL_H
  172.